home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / SNIP9_91.ARJ / ASSIGNPR.C < prev    next >
C/C++ Source or Header  |  1991-09-12  |  1KB  |  48 lines

  1. /*
  2. **  ASSIGNPR.C
  3. **
  4. **  Multiple printer support with default to a single printer
  5. **  connected to the PRN device.
  6. */
  7.  
  8. #include <stdio.h>
  9.  
  10. #define NUM_OF_PRNTRS 6
  11.  
  12. FILE *printer[NUM_OF_PRNTRS] = {stdprn};
  13.  
  14. /*
  15. **  assign_printer()
  16. **
  17. **  Call with printer number and device name
  18. **
  19. **     printer number should be in the range of 0 to NUM_OF_PRNTRS-1
  20. **     device should be "LPT1", "LPT2", "LPT3", "COM1", COM2", or a log file
  21. **
  22. **  Returns 0 if successful, -1 if error
  23. **
  24. **  Then do all printer output with fprintf(), fputs(), fputc(), etc.
  25. **  using printer[printer_number] as the output stream
  26. */
  27.  
  28. int cdecl assign_printer(int number, char *device)
  29. {
  30.       FILE *fp;
  31.  
  32.       if (NUM_OF_PRNTRS <= number || NULL == (fp = fopen(device, "w")))
  33.             return -1;
  34.       printer[number] = fp;
  35.       return 0;
  36. }
  37.  
  38. #ifdef DEBUG                                    /* Test code follows    */
  39.  
  40. main()
  41. {                                       /* Leave printer[0] = stdprn    */
  42.       assign_printer(1, "CON");         /* Set printer[1] to the screen */
  43.       assign_printer(2, "p.log");       /* Set printer[2] to log file   */
  44.       fputs("This is a printer test\n", printer[0]);
  45.       fputs("This is a screen test\n", printer[1]);
  46.       fputs("This is a log test\n", printer[2]);
  47. }
  48.